package com.nsoft.html5npub.utils;

import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * <b>ExWebViewClient</b> handles 
 * @author minhld
 *
 */
public class ExWebViewClient extends WebViewClient {
	/**
	private String[] jsFiles;
	
	public ExWebViewClient(String[] _jsFiles){
//		this.jsFiles=_jsFiles;
		this.jsFiles=new String[2];
		this.jsFiles[0]="/mnt/sdcard/pv_data/books/Lucky/js/jquery-1.6.2.min.js";
		this.jsFiles[1]="/mnt/sdcard/pv_data/books/Lucky/js/supplier.js";
	}
	*/
	
	public ExWebViewClient(){}
	
	@Override
	public boolean shouldOverrideUrlLoading(
					WebView view,String url) {

		return checkUrlType(url);
	}
	
	private boolean checkUrlType(String url){
		String urlType=url.substring(url.lastIndexOf(
				Constant.CHR_POPUPTYPE_DELIMITER)+1);
			
		if (urlType.equals(Constant.view.URL_TYPE_POPUP)){
			return true;
		}
		return true;
	}
	
	
	
	@Override
	public void onPageFinished(WebView view, String url) {
		/**
		String content;
		for (int i=0;i<this.jsFiles.length;i++){
			content=readFile(this.jsFiles[i]);
//			view.loadUrl("javascript:("+content+")()");
			
			view.loadUrl(
			"javascript:(function() { " +  
		    "var script=document.createElement('script');" +
		    "script.type='text/javascript';"+
		    "script.src='" + this.jsFiles[i]+ "';" +
		    "document.getElementsByTagName('head').item(0).appendChild(script);"+  
		    "})()");
		}
		*/
	}
	
	/**
	private String readFile(String url){
		try{
			FileInputStream fis=new FileInputStream(url);
			InputStreamReader isr=new InputStreamReader(fis);
			BufferedReader br=new BufferedReader(isr);
			StringBuffer sb=new StringBuffer();
			String line;
			while(true){
				line=br.readLine();
				if (line==null)
					break;
				sb.append(line);
			}
			br.close();
			isr.close();
			fis.close();
			return sb.toString();
		}catch(Exception e){
			return "";
		}
	}
	*/
}
